<template>
  <div class="detail-nav-bar">
    <NavBar>
      <template v-slot:left>
        <div class="nav-left" @click="backClick">
          <img src="@/assets/img/common/back.svg" alt="back" />
        </div>
      </template>
      <template v-slot:center>
        <div class="nav-center">
          <div
            @click="navClick(index)"
            class="nav-item"
            v-for="(item, index) in titles"
            :key="index"
            :class="{active: currentIndex === index}"
          >{{item}}</div>
        </div>
      </template>
    </NavBar>
  </div>
</template>

<script>
import NavBar from "@/components/common/navbar/NavBar.vue";
export default {
  name: "detail-nav-bar",
  components: {
    NavBar
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0
    };
  },
  methods: {
    navClick(index) {
      this.currentIndex = index;
      this.$emit("handleNavIndex", index);
    },
    backClick() {
      this.$router.go(-1);
    }
  }
};
</script>

<style scoped>
.nav-center {
  display: flex;
  flex-flow: row nowrap;
}
.nav-item {
  flex: 1;
  cursor: pointer;
}
.nav-item.active {
  color: var(--color-tint);
}
.nav-left {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
}
</style>